/**
 * 
 */
package controller;


import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JComponent;

/**
 * @author Leo COLLET, Nelle VAROQUAUX
 *
 */

public class DragNDrop extends JComponent implements MouseListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 
	 */

	 private static DragNDrop instance = null ;
	 protected JComponent source;
	 protected JComponent target;

	 protected DragNDrop(){
	    this.addMouseListener(this);
	    this.source = null;
	    this.target = null;
	 }

	 public static DragNDrop getInstance(){
	    if(instance == null){
		instance = new DragNDrop();
	    }
	    return instance;
	 }
	 
	 public  void addSource(JComponent dragSource){
		 this.source = dragSource;
		 System.out.println(this.source + "is dragged.");
	 }

	 public JComponent getSource(){
		System.out.println(this.source);
		return this.source;
	 }

	 public void addTarget(JComponent dropTarget){
		this.target = dropTarget;
		System.out.println(this.target + "is target.");
	 }

	 public JComponent getTarget(){
		return this.target;
	 };

	 public void removeTarget(JComponent dropTarget){
		this.target = null;
	 }

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		if(this.source != null & this.target != null){
		    System.out.println(this.source + " was dropped " +
		    this.target);
		}

		this.source = null;
		this.target = null;
	}
}
